package com.mystyle.le.qjnewsproject.MyAsyncTaks;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;

import com.mystyle.le.qjnewsproject.interfacecallback.CallBack;
import com.mystyle.le.qjnewsproject.utils.DownData;

/**
 * 异步任务下载顶部广告
 * Created by le on 2016/10/8.
 */
public class TopAsyncTaks extends AsyncTask<String,Void,Bitmap> {
    private CallBack.GetPicture getPicture;

    public TopAsyncTaks(CallBack.GetPicture getPicture) {
        this.getPicture = getPicture;
    }

    @Override
    protected Bitmap doInBackground(String... params) {
        String param = params[0];
        byte[] bytes = DownData.downTitles(param);
        if (bytes!=null&&bytes.length>0){
            Bitmap bitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length);
            return bitmap;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap) {
        super.onPostExecute(bitmap);
        if (bitmap!=null){
            getPicture.getPicture(bitmap);
        }
    }
}
